public class DFS_Test {
    static int max;
    public static void main(String[] args) {
        max = Integer.MIN_VALUE;
        int[] weight = {2, 4, 1, 5, 2},price = {4, 5, 19, 3, 2}; //重量和价值
        int all = 6; //背包总容量
        dfs(weight, price, new int[weight.length], all,0,0);
        System.out.println(max);
    }
    static void dfs(int[] weight,int[] price,int[] used,int all,int now,int nowPrice){
        if (now>all)
            return;
        max = Math.max(nowPrice,max);
        for (int i = 0; i < weight.length; i++)
            if (used[i]==0){
                used[i] = 1;
                dfs(weight, price, used, all, now+weight[i],nowPrice+price[i]);
                used[i] = 0;
            }
    }
}
